<?php
/*
 * Created on 22.12.2005
 *
 */

/**
 * attributes:
 * 
 * id: id of html element to insert before, after, as first or last child
 */
class ajax_insertHtmlHandler
{
    
    var $id = null;
    /**
     * modes:
     * before - as previous sibling of node
     * after  - as next sibling of node
     * first  - add as first child
     * last   - add as last child
     */
    var $mode = null;
    /**
     * effects:
     * fade          - fade in -> needs duration
     * fadehighlight - fade in, then highlight -> needs color, duration (duration for highlight, half for fadein)
     * wipe          - wipe in -> needs duration
     * wipehighlight - wipe in, then highlight -> needs color, duration (duration for highlight, one fourth for wipein)
     * highlight     - highlight -> needs color, duration
     */
    var $effect = null;
    var $duration = null;
    var $color = null;

    function startElement (& $sender, $attrs, $line)
    {
        if (empty($attrs['id']))
            $sender->appendCode('$out->write("alert(\'Attribute id is missing in tag ajax:insertHtml in line '.$line.'!\');");');
        else
        {
            $this->id = $attrs['id'];
            if (empty($attrs['mode']))
                $this->mode = 'last';
            else
                $this->mode = $attrs['mode'];
            if (!empty($attrs['effect']))
                $this->effect = $attrs['effect'];
            if (!empty($attrs['duration']))
                $this->duration = $attrs['duration'];
            if (empty($attrs['color']))
                $this->color = "'252, 252, 0'";
            else
                $this->color = $attrs['color'];
            // TODO Check this!! (addWidgetSearchId)
            $sender->appendCode('$out->write("phpinchains.addWidgetSearchId('.$attrs['id'].');insertHtml.".'.$this->mode.'."(function (node) {");');
        }
    }

    function endElement (& $sender)
    {
        if ($this->id != null)
        {
            $sender->appendCode(' $out->write( "');
            $sender->appendCode('},\'".str_replace("\'", "\\\'",str_replace("\r", " ", str_replace("\n", " ", $__replacement)))."\', dojo.byId('.$this->id.')');
            $sender->appendCode(",".($this->effect ? $this->effect : "''").",".'".'.($this->duration ? $this->duration : "'100'").'."'.",".'[".'.($this->color ? $this->color : "''").'."]'.');");');
        }
        $this->effect   = null;
        $this->mode     = null;
        $this->duration = null;
        $this->id       = null;
    }

}

?>